package com.geek.javase.ch07.strings;

/*
 *@author wangpeng
 *2025/10/15 15:51
 *@description TODO
 */
/**
 * 1.使用System类获取当前系统的毫秒值
 * 统计代码的执行时间，String拼接+  、StringBuilder拼接
 */
public class StringBuilderDemo1 {
    public static void main(String[] args) {
        long startTime1 = System.currentTimeMillis();
        System.out.println(startTime1);
        String str = "w";
        for (int i = 0; i < 10000; i++) {
            str += "a";
        }
        long endTime1 = System.currentTimeMillis();
        System.out.println("使用String拼接执行的时间：" + (endTime1 - startTime1));

        long startTime2 = System.currentTimeMillis();
        StringBuilder sb = new StringBuilder("a");
        for (int i = 0; i < 10000; i++) {
            sb.append("a");
        }
        long endTime2 = System.currentTimeMillis();
        System.out.println("使用StringBuilder拼接执行的时间：" + (endTime2 - startTime2));
    }
}
